package com.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.entity.Wupinxinxi;
import com.service.WupinxinxiService;
import com.utils.R;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 物品信息
 * 后端接口
 * @author
 * @email
 * @date 2025-02-17 16:19:48
 */
@RestController
@RequestMapping("/wupinxinxi")
public class WupinxinxiController {

    @Resource
    private WupinxinxiService wupinxinxiService;

    /**
     * 后端列表
     */
    @RequestMapping("/page")
    public R page(Wupinxinxi wupinxinxi, HttpServletRequest request){
        Page page = wupinxinxiService.page(wupinxinxi);
        return R.ok().put("data", page);
    }




    /**
     * 查询详情
     */
    @RequestMapping("/info")
    public R info(@RequestParam("id") Long id){
        Wupinxinxi wupinxinxi = wupinxinxiService.selectById(id);
        return R.ok().put("data", wupinxinxi);
    }





    /**
     * 添加
     */
    @RequestMapping("/save")
    public R save(@RequestBody Wupinxinxi wupinxinxi, HttpServletRequest request){
        wupinxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
        //ValidatorUtils.validateEntity(beiwanglu);
        wupinxinxiService.insert(wupinxinxi);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody Wupinxinxi wupinxinxi, HttpServletRequest request){
        //ValidatorUtils.validateEntity(beiwanglu);
        wupinxinxiService.updateById(wupinxinxi);//全部更新
        return R.ok();
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody List<Long> ids){
        wupinxinxiService.deleteBatchIds(ids);
        return R.ok();
    }


}
